package de.hwr.sudokuspielehr.ui.listener;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import de.hwr.sudokuspielehr.ui.UserInterface;
import de.hwr.sudokuspielehr.ui.component.SudokuCellPanel;

/**
 * 
 * @author J. Reischauer
 * 
 */
public class SudokuCellPanelListener implements MouseListener {

	/**
	 * UserInterface instance.
	 */
	private UserInterface ui;

	/**
	 * Constructor of SudokuCellPanelListener
	 * 
	 * @param pUi
	 */
	public SudokuCellPanelListener(UserInterface pUi) {
		ui = pUi;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		Component c = e.getComponent();

		if (c instanceof SudokuCellPanel) {
			SudokuCellPanel cellPanel = (SudokuCellPanel) c;

			if (cellPanel.isEditable()) {
				SudokuCellPanel lastClicked = ui.getLastClicked();

				if (lastClicked != null) {
					lastClicked.setSelected(false);
				}

				cellPanel.setSelected(true);
				ui.setLastClicked(cellPanel);
			}
		}
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
